package org.xbs.demo1.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.xbs.demo1.mapper.LoginMapper;
import org.xbs.demo1.pojo.JwtUtils;
import org.xbs.demo1.pojo.LoginBackParam;
import org.xbs.demo1.pojo.LoginParam;
import org.xbs.demo1.service.ILoginService;

@Service
public class LoginService implements ILoginService {
    @Autowired
    private LoginMapper loginMapper;
    @Override
    public LoginBackParam login(LoginParam loginParam) {
      //调用loginMapper中的login()方法,并用loginBackParam接收返回值
        LoginBackParam loginBackParam = loginMapper.login(loginParam);
        //判断这个返回值是否为null值，即判断这个用户是否存在
        if(loginBackParam==null){
            return null;
        }
        //不为null值，则创建jwt令牌并赋值给token元素
        loginBackParam.setToken(JwtUtils.generatejws(loginBackParam));
        return loginBackParam;

    }
}
